#ifndef WELCOMEWIDGET_H
#define WELCOMEWIDGET_H

#include <QWidget>
#include <stdio.h>
#include <string.h>
#include <QDebug>
#include <QDateTime>
#include <QVBoxLayout>
#include <QTimer>
#include <QtEndian>

#include "circle_queue.h"
#include "wifi_connect.h"
#include "serial_port/serial_port.h"
#include "serial_port/serial_tx_thread.h"
#include "serial_port/serial_rx_thread.h"
#include "serial_port/rs485_1_tx_thread.h"
#include "serial_port/rs485_1_rx_thread.h"

namespace Ui {
class WelcomeWidget;
}

class Page1_Widget;
class Page2_Widget;
class Page3_Widget;
class Page4_Widget;
class Page5_Widget;

#define SOFTWARE_VERSION     "V 1.0.0"
#define HARDWARE_VERSION     "V 1.0.2"

#define COMPANY_INFO         "EmbedIoT Studio "


#define TIMEOUT_BASE_VALUE           100                  //200ms
#define TIMEOUT_CURRTIME_UPDATE      1000                 //1000ms

#define  USB_TTL_SERIAL_PORT               "/dev/ttyUSB0"
#define  RS485_SERIAL_PORT                 "/dev/ttymxc2"

class WelcomeWidget : public QWidget
{
    Q_OBJECT

public:
    explicit WelcomeWidget(QWidget *parent = nullptr);
    ~WelcomeWidget();
    Ui::WelcomeWidget *ui;

    Serial_Tx_Thread *m_serial_tx_thread;
    QThread *m_tx_thread;

    Serial_Rx_Thread *m_serial_rx_thread;
    QThread *m_rx_thread;

    RS485_1_Tx_Thread *m_rs485_1_tx_thread;
    QThread *m_485_1tx_thread;

    RS485_1_Rx_Thread *m_rs485_1_rx_thread;
    QThread *m_485_1rx_thread;


signals:
    void signal_start_sp_tx_thread();
    void signal_start_sp_rx_thread();

    void signal_start_rs485_1_tx_thread();
    void signal_start_rs485_1_rx_thread();

private slots:
    void basetimer_timeout_handler();

    void on_pb_page_1_clicked();
    void on_pb_page_2_clicked();
    void on_pb_page_3_clicked();
    void on_pb_page_4_clicked();
    void on_pb_page_5_clicked();

private:
    QTimer *base_timer;
    Serial_Port *wireless_serial;
    Serial_Port *rs485_1_serial;
    WiFi_Connect *m_wifi;

    Page1_Widget *page1_widget;
    Page2_Widget *page2_widget;
    Page3_Widget *page3_widget;
    Page4_Widget *page4_widget;
    Page5_Widget *page5_widget;

    void update_current_time();
    void update_information();
    void start_serial_port();
    void start_serial_port_thread();

    void start_rs485_1_serial_port();
    void start_rs485_1_serial_port_thread();
};

#endif // WELCOMEWIDGET_H
